package com.trt.beibei.model;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;

/**
 * 商品实体类
 */
@Entity
@Getter
@Setter
@Where(clause = "delete_time is null and online = 1 ") // 软删除查询的方案，但是不是很好，缺点不够灵活
public class Spu extends BaseEntity {

    @Id
    private Long id;
    private String title;
    private String subtitle;
    private Long categoryId;
    private Long rootCategoryId;
    private Boolean online;
    private String price;
    private Long sketchSpecId;
    private Long defaultSkuId;
    private String img;
    private String discountPrice;
    private String description;
    private String tags;
    private Boolean isTest;

    // private Object spuThemeImg;
    private String forThemeImg;

    /**
     * 导航关系的配置原则 （在一方配置单项导航或者另一方配置单向导航或者双向导航关系）
     * 1.需要时才配置
     * 如已知一个spu获取spu下的SpuDetailImg配置导航关系；
     * 不确定SpuDetailImg需要spu，就不配置导航关系，如果开发时需要配置再配置导航关系
     */

    // 配置导航关系
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "spuId")
    private List<Sku> skuList;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "spuId")
    private List<SpuImg> spuImgList;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "spuId")
    private List<SpuDetailImg> spuDetailImgList;


}
